<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>JavaScript(1) | Celts</title><meta name="author" content="PaulGeorge"><meta name="copyright" content="PaulGeorge"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="数据类型数值、文本、图形、音频、视频…js不区分小数和整数 number  字符串&amp;#x27;a&amp;#x27; 、&quot;a&quot;">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript(1)">
<meta property="og:url" content="https://curry3035.gitee.io/posts/13958/index.html">
<meta property="og:site_name" content="Celts">
<meta property="og:description" content="数据类型数值、文本、图形、音频、视频…js不区分小数和整数 number  字符串&amp;#x27;a&amp;#x27; 、&quot;a&quot;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://curry3035.gitee.io/img/avatar.jpg">
<meta property="article:published_time" content="2020-05-23T04:24:34.000Z">
<meta property="article:modified_time" content="2021-10-26T14:26:00.121Z">
<meta property="article:author" content="PaulGeorge">
<meta property="article:tag" content="脚本语言">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://curry3035.gitee.io/img/avatar.jpg"><link rel="shortcut icon" href="/img/ic.ico"><link rel="canonical" href="https://curry3035.gitee.io/posts/13958/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":false,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: PaulGeorge","link":"链接: ","source":"来源: Celts","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'JavaScript(1)',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-10-26 22:26:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/background.css"><link rel="stylesheet" href="/css/my.css"><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="Celts"><span class="site-name">Celts</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">JavaScript(1)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-05-23T04:24:34.000Z" title="发表于 2020-05-23 12:24:34">2020-05-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-10-26T14:26:00.121Z" title="更新于 2021-10-26 22:26:00">2021-10-26</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">527</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>2分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="JavaScript(1)"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h4 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h4><h5 id="数值、文本、图形、音频、视频…"><a href="#数值、文本、图形、音频、视频…" class="headerlink" title="数值、文本、图形、音频、视频…"></a>数值、文本、图形、音频、视频…</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">js不区分小数和整数 number</span><br></pre></td></tr></table></figure>

<h5 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="string">&#x27;a&#x27;</span> 、<span class="string">&quot;a&quot;</span></span><br></pre></td></tr></table></figure>

<span id="more"></span>

<h5 id="布尔"><a href="#布尔" class="headerlink" title="布尔"></a>布尔</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="literal">true</span> 、 <span class="literal">false</span></span><br></pre></td></tr></table></figure>



<h5 id="逻辑运算"><a href="#逻辑运算" class="headerlink" title="逻辑运算"></a>逻辑运算</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&amp;&amp;			都真为真</span><br><span class="line">||			一个为真，结果为真</span><br><span class="line">!			真即假，假即真</span><br></pre></td></tr></table></figure>



<h5 id="比较"><a href="#比较" class="headerlink" title="比较"></a>比较</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">=</span><br><span class="line">==			等于(类型不同，值相同，结果判断为<span class="literal">true</span>)</span><br><span class="line">===			绝对等于(类型相同，值相同，结果判断为<span class="literal">true</span>)</span><br></pre></td></tr></table></figure>

<blockquote>
<p>最好使用===</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">注意: <span class="title class_">NaN</span> === <span class="title class_">NaN</span> ,这个值与所有的值都不相等，包括自己</span><br></pre></td></tr></table></figure>



<h4 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h4><h5 id="Java的数组中类型必须相同类型的对象，JS中不需要这样"><a href="#Java的数组中类型必须相同类型的对象，JS中不需要这样" class="headerlink" title="Java的数组中类型必须相同类型的对象，JS中不需要这样"></a>Java的数组中类型必须相同类型的对象，JS中不需要这样</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="string">&#x27;hello word&#x27;</span>,<span class="literal">null</span>,<span class="literal">true</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Arry</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="string">&#x27;hello word&#x27;</span>,<span class="literal">null</span>,<span class="literal">true</span>);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>如果数组下标越界，显示 undefined</p>
</blockquote>
<h4 id="对象"><a href="#对象" class="headerlink" title="对象"></a>对象</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">对象是大括号，数组是中括号，最后一个不需要添加</span><br></pre></td></tr></table></figure>



<h4 id="取对象值"><a href="#取对象值" class="headerlink" title="取对象值"></a>取对象值</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">链式取值，通过对象·的方式</span><br></pre></td></tr></table></figure>



<h4 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> 	全局变量</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> 	局部变量</span><br></pre></td></tr></table></figure>



<h4 id="数据"><a href="#数据" class="headerlink" title="数据"></a>数据</h4><h5 id="1、多行编写"><a href="#1、多行编写" class="headerlink" title="1、多行编写"></a>1、多行编写</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> msg = </span><br><span class="line">    <span class="string">`hello</span></span><br><span class="line"><span class="string">	word</span></span><br><span class="line"><span class="string">	!`</span></span><br></pre></td></tr></table></figure>

<h5 id="2、字符串长度"><a href="#2、字符串长度" class="headerlink" title="2、字符串长度"></a>2、字符串长度</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">str.<span class="property">length</span></span><br></pre></td></tr></table></figure>

<h5 id="3、substring"><a href="#3、substring" class="headerlink" title="3、substring"></a>3、substring</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">[)</span><br><span class="line"> str.<span class="title function_">substring</span>(<span class="number">1</span>)	<span class="comment">//从第一个字符截取到最后一个字符</span></span><br><span class="line"> str.<span class="title function_">substring</span>(<span class="number">1</span>,<span class="number">3</span>)		<span class="comment">//[1,3])</span></span><br></pre></td></tr></table></figure>



<h4 id="数组-1"><a href="#数组-1" class="headerlink" title="数组"></a>数组</h4><h5 id="Array可以包含任意类型的数据类型"><a href="#Array可以包含任意类型的数据类型" class="headerlink" title="Array可以包含任意类型的数据类型"></a>Array可以包含任意类型的数据类型</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>]</span><br></pre></td></tr></table></figure>

<h5 id="1、长度"><a href="#1、长度" class="headerlink" title="1、长度"></a>1、长度</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">arr.<span class="property">length</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>注意：加入给 arr.length 赋值，数组大小会发生变化，如果数值小于元素个数，元素就会丢失</p>
</blockquote>
<h5 id="2、indexOf，通过元素下标获得索引"><a href="#2、indexOf，通过元素下标获得索引" class="headerlink" title="2、indexOf，通过元素下标获得索引"></a>2、indexOf，通过元素下标获得索引</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">arr.<span class="title function_">indexOf</span>(<span class="number">2</span>)</span><br><span class="line">字符串 <span class="string">&quot;1&quot;</span> 和数字 <span class="number">1</span> 是不同的</span><br></pre></td></tr></table></figure>

<h5 id="3、slice-截取Array的一部分，功能强大的方法，返回一个新的数字"><a href="#3、slice-截取Array的一部分，功能强大的方法，返回一个新的数字" class="headerlink" title="3、slice() 截取Array的一部分，功能强大的方法，返回一个新的数字"></a>3、slice() 截取Array的一部分，功能强大的方法，返回一个新的数字</h5><h5 id="4、push-，shift-头部"><a href="#4、push-，shift-头部" class="headerlink" title="4、push() ，shift() 头部"></a>4、push() ，shift() 头部</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="attr">unshift</span>: 压入头部</span><br><span class="line"><span class="attr">shift</span>: 弹出头部的一个元素</span><br></pre></td></tr></table></figure>

<h5 id="5、排序-sort"><a href="#5、排序-sort" class="headerlink" title="5、排序 sort()"></a>5、排序 sort()</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">[<span class="string">&quot;B&quot;</span>,<span class="string">&quot;C&quot;</span>,<span class="string">&quot;A&quot;</span>]</span><br><span class="line">arr.<span class="title function_">sort</span>()</span><br><span class="line">[<span class="string">&quot;A&quot;</span>,<span class="string">&quot;B&quot;</span>,<span class="string">&quot;C&quot;</span>]</span><br></pre></td></tr></table></figure>

<h5 id="6、元素反转-reverse"><a href="#6、元素反转-reverse" class="headerlink" title="6、元素反转 reverse()"></a>6、元素反转 reverse()</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">[<span class="string">&quot;A&quot;</span>,<span class="string">&quot;B&quot;</span>,<span class="string">&quot;C&quot;</span>]</span><br><span class="line">arr.<span class="title function_">reverse</span>()</span><br><span class="line">[<span class="string">&quot;C&quot;</span>,<span class="string">&quot;B&quot;</span>,<span class="string">&quot;A&quot;</span>]</span><br></pre></td></tr></table></figure>

<h5 id="7、concat"><a href="#7、concat" class="headerlink" title="7、concat()"></a>7、concat()</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">[<span class="string">&quot;A&quot;</span>,<span class="string">&quot;B&quot;</span>,<span class="string">&quot;C&quot;</span>]</span><br><span class="line">arr.<span class="title function_">concat</span>([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])</span><br><span class="line">[<span class="string">&quot;A&quot;</span>,<span class="string">&quot;B&quot;</span>,<span class="string">&quot;C&quot;</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">注意: <span class="title function_">concat</span>()并没有修改数据，只是返回一个新的数组</span><br></pre></td></tr></table></figure>

<h5 id="8、join"><a href="#8、join" class="headerlink" title="8、join()"></a>8、join()</h5><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">[<span class="string">&quot;A&quot;</span>,<span class="string">&quot;B&quot;</span>,<span class="string">&quot;C&quot;</span>]</span><br><span class="line">arr.<span class="title function_">join</span>(<span class="string">&#x27;-&#x27;</span>)</span><br><span class="line"><span class="string">&quot;A-B-C&quot;</span></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io">PaulGeorge</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io/posts/13958/">https://curry3035.gitee.io/posts/13958/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://curry3035.gitee.io" target="_blank">Celts</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E8%84%9A%E6%9C%AC%E8%AF%AD%E8%A8%80/">脚本语言</a></div><div class="post_share"><div class="social-share" data-image="/img/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/50822/" title="JavaScript(2)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">JavaScript(2)</div></div></a></div><div class="next-post pull-right"><a href="/posts/6541/" title="CSS"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">CSS</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/63260/" title="JQuery"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-05-23</div><div class="title">JQuery</div></div></a></div><div><a href="/posts/22151/" title="JavaScript(3)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-05-23</div><div class="title">JavaScript(3)</div></div></a></div><div><a href="/posts/50822/" title="JavaScript(2)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-05-23</div><div class="title">JavaScript(2)</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">PaulGeorge</div><div class="author-info__description">很多事情就像是旅行一样，当你决定要出发的时候，最困难的那部分其实就已经完成了</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/PaulGeorge123"><i class="fab fa-github"></i><span>GitHub URL</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/PaulGeorge123" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%95%B0%E5%80%BC%E3%80%81%E6%96%87%E6%9C%AC%E3%80%81%E5%9B%BE%E5%BD%A2%E3%80%81%E9%9F%B3%E9%A2%91%E3%80%81%E8%A7%86%E9%A2%91%E2%80%A6"><span class="toc-number">1.1.</span> <span class="toc-text">数值、文本、图形、音频、视频…</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">1.2.</span> <span class="toc-text">字符串</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%B8%83%E5%B0%94"><span class="toc-number">1.3.</span> <span class="toc-text">布尔</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97"><span class="toc-number">1.4.</span> <span class="toc-text">逻辑运算</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%AF%94%E8%BE%83"><span class="toc-number">1.5.</span> <span class="toc-text">比较</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E7%BB%84"><span class="toc-number">2.</span> <span class="toc-text">数组</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Java%E7%9A%84%E6%95%B0%E7%BB%84%E4%B8%AD%E7%B1%BB%E5%9E%8B%E5%BF%85%E9%A1%BB%E7%9B%B8%E5%90%8C%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%AF%B9%E8%B1%A1%EF%BC%8CJS%E4%B8%AD%E4%B8%8D%E9%9C%80%E8%A6%81%E8%BF%99%E6%A0%B7"><span class="toc-number">2.1.</span> <span class="toc-text">Java的数组中类型必须相同类型的对象，JS中不需要这样</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AF%B9%E8%B1%A1"><span class="toc-number">3.</span> <span class="toc-text">对象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8F%96%E5%AF%B9%E8%B1%A1%E5%80%BC"><span class="toc-number">4.</span> <span class="toc-text">取对象值</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8F%98%E9%87%8F"><span class="toc-number">5.</span> <span class="toc-text">变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE"><span class="toc-number">6.</span> <span class="toc-text">数据</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81%E5%A4%9A%E8%A1%8C%E7%BC%96%E5%86%99"><span class="toc-number">6.1.</span> <span class="toc-text">1、多行编写</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2%E3%80%81%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6"><span class="toc-number">6.2.</span> <span class="toc-text">2、字符串长度</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3%E3%80%81substring"><span class="toc-number">6.3.</span> <span class="toc-text">3、substring</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E7%BB%84-1"><span class="toc-number">7.</span> <span class="toc-text">数组</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#Array%E5%8F%AF%E4%BB%A5%E5%8C%85%E5%90%AB%E4%BB%BB%E6%84%8F%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">7.1.</span> <span class="toc-text">Array可以包含任意类型的数据类型</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81%E9%95%BF%E5%BA%A6"><span class="toc-number">7.2.</span> <span class="toc-text">1、长度</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2%E3%80%81indexOf%EF%BC%8C%E9%80%9A%E8%BF%87%E5%85%83%E7%B4%A0%E4%B8%8B%E6%A0%87%E8%8E%B7%E5%BE%97%E7%B4%A2%E5%BC%95"><span class="toc-number">7.3.</span> <span class="toc-text">2、indexOf，通过元素下标获得索引</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3%E3%80%81slice-%E6%88%AA%E5%8F%96Array%E7%9A%84%E4%B8%80%E9%83%A8%E5%88%86%EF%BC%8C%E5%8A%9F%E8%83%BD%E5%BC%BA%E5%A4%A7%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E6%95%B0%E5%AD%97"><span class="toc-number">7.4.</span> <span class="toc-text">3、slice() 截取Array的一部分，功能强大的方法，返回一个新的数字</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4%E3%80%81push-%EF%BC%8Cshift-%E5%A4%B4%E9%83%A8"><span class="toc-number">7.5.</span> <span class="toc-text">4、push() ，shift() 头部</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5%E3%80%81%E6%8E%92%E5%BA%8F-sort"><span class="toc-number">7.6.</span> <span class="toc-text">5、排序 sort()</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#6%E3%80%81%E5%85%83%E7%B4%A0%E5%8F%8D%E8%BD%AC-reverse"><span class="toc-number">7.7.</span> <span class="toc-text">6、元素反转 reverse()</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#7%E3%80%81concat"><span class="toc-number">7.8.</span> <span class="toc-text">7、concat()</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#8%E3%80%81join"><span class="toc-number">7.9.</span> <span class="toc-text">8、join()</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/47231/" title="POI读取Excel问题">POI读取Excel问题</a><time datetime="2023-04-11T01:00:00.000Z" title="发表于 2023-04-11 09:00:00">2023-04-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/8422/" title="Excel大文件的上传">Excel大文件的上传</a><time datetime="2023-04-10T01:00:00.000Z" title="发表于 2023-04-10 09:00:00">2023-04-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/55119/" title="每日一面--Files工具类">每日一面--Files工具类</a><time datetime="2023-01-01T01:00:00.000Z" title="发表于 2023-01-01 09:00:00">2023-01-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/34600/" title="面试一下--JUC入门">面试一下--JUC入门</a><time datetime="2022-09-10T01:00:00.000Z" title="发表于 2022-09-10 09:00:00">2022-09-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/16284/" title="每日一面--字符流和字节流">每日一面--字符流和字节流</a><time datetime="2022-07-01T01:00:00.000Z" title="发表于 2022-07-01 09:00:00">2022-07-01</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By PaulGeorge</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>